use std::fmt;
use tauri::ipc::InvokeError;

#[derive(Debug)]
pub enum CustomErr {
    Io(std::io::Error),
}

// 从 std::io::Error 自动转换
impl From<std::io::Error> for CustomErr {
    // io路径转自定义错误
    fn from(err: std::io::Error) -> Self {
        CustomErr::Io(err)
    }
}

// 格式化输出
impl fmt::Display for CustomErr {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            CustomErr::Io(e) => write!(f, "文件系统错误: {}", e),
        }
    }
}

impl From<CustomErr> for InvokeError {
    fn from(err: CustomErr) -> Self {
        InvokeError::from(err.to_string()) // 把你的错误转换成字符串形式的 InvokeError
    }
}
